applescript to open safari in private browsing
Hello,
I've read an old locked discussion from year 2010 but the script provided there does not work. Could anyone help me please ? I'm not familiar with scripting. Thanks.
OS X El Capitan (10.11.1)
Hello,
I've read an old locked discussion from year 2010 but the script provided there does not work. Could anyone help me please ? I'm not familiar with scripting. Thanks.
OS X El Capitan (10.11.1)
the non-working script is :
tell application "Safari" to activate
tell application "System Events" to tell process "Safari"
if menu item "Private Browsing…" of menu 1 of menu bar item 2 of menu bar 1 exists then
click menu item "Private Browsing…" of menu 1 of menu bar item 2 of menu bar 1
keystroke return
else
click menu item "Private Browsing" of menu 1 of menu bar item 2 of menu bar 1
end if
end tell
If your goal is to just open a Private Browsing window in Safari 9, then the terminology has changed to New Private Window, and that old script is broke and pointless, when all you have to do in Safari is press shift+command+N to launch that New Private Window.
This code just opens a New Private Window in Safari 9, something that the majority of us that need that functionality could do with shift+command+N.
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
keystroke "N" using {shift down, command down}
end tell
end tell
endtell
Thank you.
Very good, working fine!! Thanks very much.
By the way, do you know by chance how to open it in a small window, rather than in full screen mode?
And do you know how I can figure out the resolution of default icons for application so I can have an icon same resolution for the new app? I didn't find it.
Thanks.
When I run this script as written on OS X 10.11.6 with Safari 9.1.2, the new private window opens at a normal Safari window size — not full screen.
If I quit Safari that has been opened full screen, and run this script again, paragraph 1 is still the result.
Here is a script that creates a new private window of user configurable proportions:
use scripting additions
set position to {0, 0, 800, 800} as bounding rectangle
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
keystroke "N" using {shift down, command down}
end tell
end tell
set bounds of front window to position
end tell
Hi,
Thanks for the quick reply but the script's behaviour is weird!
In fact, Safari opens in full screen mode but the display part takes the size you define in the full screen, and the remaining is black, like a small window in the big one!!!
Really Weird!!
This is intended for Safari 9.* on Mavericks 10.9.5 or later. It works fine on my system as mentioned in the previous post. I should have added:
use AppleScript version "2.3" to the script which would have restricted it to Mavericks or later.
Yes I have latest OSX 10.11.6 (15G31) and Safari 9.1.2 (11601.7.7)
But I have Script Editor Version 2.8.1 (183.1) and AppleScript 2.5, is it a problem?
Thx
You have what I have. There is no problem, as this is what I tested my script against.
Had I specified use AppleScript version "2.3", that means it would be the minimum allowable version for the script, and restrict its running to Mavericks 10.9.5 or later — where Safari 9.* exists.
applescript to open safari in private browsing